<template>
	<view>
		<!-- 头部导航 -->
		<page-header :headInfo="headInfo"></page-header>
		<view>
			<scroll-view class="atlas-list" :id="scrollId" :scroll-y="isScroll" @scroll="scroll" @scrolltolower="scrolltolower" v-if="collextsList.length > 0">
				<view v-for="item in collextsList" class="atlas-image">
					<lazy-load
							:key="imgPath + item.imgUrl"
							:src="imgPath + item.imgUrl"
							:content="content"
							:atlasId="item.id"
							:scroll-id="'#'+scrollId"
							@controlRoll="controlRoll"
							@refresh="refresh"
							mode="aspectFill"></lazy-load>
				</view>
			</scroll-view>
			
			<view v-if="collextsList.length < 1" style="text-align: center;padding: 30rpx 0;">暂无收藏</view>
		</view>
	</view>
</template>

<script>
	import lazyLoad from '../../components/lazyLoad/index';
	import lazyLoadPlugin from '../../plugins/lazyLoad/js/index';
	export default {
		data() {
			return {
				scrollId: "scroll",
				imgPath:this.imgPath,
				headInfo:{
					title:'我的收藏'
				},
				collextsList:[],
				pages:0,
				isScroll:true,
				content:[
					{
						text:'反馈',
						status:1
					},{
						text:'删除',
						status:3
					}
				]
			}
		},
		onLoad() {
			this.collextList();
		},
		/**
		 * @author smallfour
		 * @description 分享好友
		 */
		onShareAppMessage(res){
			return {
				title:'四叶图集',
				imageUrl:'http://image.hermit.love/IMG_3494.JPG',
				path:'/pages/index/index'
			}
		},
		/**
		 * @author smallfour
		 * @description 分享朋友圈
		 */
		onShareTimeline(){
			return {
				title:'四叶图集',
				imageUrl:'http://image.hermit.love/IMG_3494.JPG',
				path:'/pages/index/index'
			}
		},
		methods: {
			refresh:function(){
				this.pages = 0;
				this.collextList();
			},
			controlRoll:function(){
				this.isScroll = this.isScroll ? false : true
			},
			scroll () {
				lazyLoadPlugin.scroll();
			},
			// 滚动置底
			scrolltolower(){
				this.collextList();
			},
			/**
			 * @author smallfour
			 * @description 我的收藏列表
			 */
			collextList:function(){
				this.pages = this.pages + 1
				let collextObj = {
					pages:this.pages,
					sizes:20
				}
				this.$api.myCollect(collextObj).then(res => {
					if(this.pages === 1){
						this.collextsList = res.data ? res.data : [];
					}else{
						// this.collextsList = this.collextsList.concat(res.data);
						this.collextsList = [... this.collextsList , ... res.data];
					}
					lazyLoadPlugin.init({
					    id: '#scroll'
					});
				}).catch(err => {
					console.log(err);
				})
			}
		},
		components: {
		    lazyLoad
		},
		destroyed () {
		    lazyLoadPlugin.destroy();
		},
		onReachBottom(){
			this.collextList();
		}
	}
</script>

<style lang="scss">
	.atlas-list{
		display: flex;
		flex-wrap:wrap;
        align-items: start;
		.atlas-image{
			width:50%;
			// width: calc(50% - 30rpx);
			margin-top: 30rpx;
			display: inline-block;
			// image{
			// 	width: 100%;
			// 	height: 240rpx;
			// 	display: block;
			// 	border: 4rpx solid #000;
			// 	border-radius: 8rpx;
			// }
		}
		.atlas-image:nth-child(odd){
			padding: 0 10rpx 0 20rpx;
		}
		.atlas-image:nth-child(even){
			padding: 0 20rpx 0 10rpx;
		}
	}

    #scroll {
        // background: #e8e8e8;
        // height: calc(100vh - 480rpx);
        height: calc(100vh - 60px - var(--status-bar-height));
    }
	.component-img-lazyload {
	    box-shadow: 0 2upx 12upx rgba(0, 0, 0, 0.2);
	    background: #fff;
	    // min-width: calc(50% - 160upx);
	    min-height: 240upx;
	    // padding: 40upx;
	    // margin: 40upx;
	    border-radius: 20upx;
		line-height: 0;
	
	    /deep/ .img {
	        width: 100%;
			height: 240rpx;
	        border-radius: 14upx;
	    }
	}
</style>
